package com.packenius.library.xspdf;

import java.net.URL;

/**
 * A link to a destination name or to a URI.
 * @author Christian Packenius, 2013.
 */
class XSLink {
  final String destinationName;

  final URL url;

  final double borderSize;

  XSLink(String destinationName, double borderSize) {
    this.destinationName = destinationName;
    url = null;
    this.borderSize = borderSize;
  }

  XSLink(URL url, double borderSize) {
    destinationName = null;
    this.url = url;
    this.borderSize = borderSize;
  }

  /**
   * @see java.lang.Object#equals(java.lang.Object)
   */
  @Override
  public boolean equals(Object obj) {
    if (obj == null || !(obj instanceof XSLink)) {
      return false;
    }
    XSLink obj2 = (XSLink) obj;
    if (destinationName != null && !destinationName.equals(obj2.destinationName)) {
      return false;
    }
    if (url != null && !url.equals(obj2.url)) {
      return false;
    }
    return true;
  }

  /**
   * @see java.lang.Object#hashCode()
   */
  @Override
  public int hashCode() {
    if (destinationName != null) {
      return destinationName.hashCode();
    } else {
      return url.hashCode();
    }
  }

  @Override
  public String toString() {
    if (destinationName != null) {
      return "Link[" + destinationName + "]";
    }
    return "URL-Link[" + url.toString() + "]";
  }
}
